package de.listrong.da.metainfo.datamodel;

import de.listrong.da.ontology.util.WriteToABox;
import de.listrong.da.ontology.FileSource;

import java.util.List;

import com.hp.hpl.jena.ontology.*;

/**
 * Created by IntelliJ IDEA.
 * User: Qiang
 * Date: 10.11.2008
 * Time: 16:05:44
 */
public class MetaInfo {
    private String sourceType;
    private String titleText;
    private List<Author> authorList;
    private String publishYear;
    private String publishCity;

    private String publisher;

    public String getSourceType() {
        return sourceType;
    }

    public void setSourceType(String sourceType) {
        this.sourceType = sourceType;
    }

    public String getTitleText() {
        return titleText;
    }

    public void setTitleText(String titleText) {
        this.titleText = titleText;
    }

    public List<Author> getAuthorList() {
        return authorList;
    }

    public void setAuthorList(List<Author> authorList) {
        this.authorList = authorList;
    }

    public String getPublishYear() {
        return publishYear;
    }

    public void setPublishYear(String publishYear) {
        this.publishYear = publishYear;
    }

    public String getPublishCity() {
        return publishCity;
    }

    public void setPublishCity(String publishCity) {
        this.publishCity = publishCity;
    }

    public String getPublisher() {
        return publisher;
    }

    public void setPublisher(String publisher) {
        this.publisher = publisher;
    }


    public MetaInfo() {
        //default constructor 
    }

    public MetaInfo(String sourceType, String titleText, List<Author> authorList, String publishYear, String publishCity, String publisher) {
        this.sourceType = sourceType;
        this.titleText = titleText;
        this.authorList = authorList;
        this.publishYear = publishYear;
        this.publishCity = publishCity;
        this.publisher = publisher;
    }

    @Override
    public String toString() {
        return "MetaInfo: [" +
                "type:"+ sourceType +
                " title:" + titleText +
                " year:" + publishYear +
                " city" + publishCity +
                " publisher" + publisher +
                "]";
    }

    public void wirtToAbox(OntModel tbox, OntModel abox, Individual parent) {
        String tBoxDefaultNS = tbox.getNsPrefixURI("");
		String aBoxNS = abox.getNsPrefixURI("");

        DatatypeProperty titleProp = tbox.getDatatypeProperty(tBoxDefaultNS + "hasTitle");
        parent.addProperty(titleProp, this.getTitleText());

        DatatypeProperty sourceTypeProp = tbox.getDatatypeProperty(tBoxDefaultNS + "sourceTypeValue");
        parent.addProperty(sourceTypeProp, this.getSourceType());

        DatatypeProperty publisherProp = tbox.getDatatypeProperty(tBoxDefaultNS + "publisherName");
        parent.addProperty(publisherProp, this.getPublisher());

        DatatypeProperty cityProp = tbox.getDatatypeProperty(tBoxDefaultNS + "publishCity");
        parent.addProperty(cityProp, this.getPublishCity());

        DatatypeProperty yearProp = tbox.getDatatypeProperty(tBoxDefaultNS + "publishYear");
        parent.addProperty(yearProp, this.getPublishYear());

        OntClass authorClass = tbox.getOntClass(tBoxDefaultNS + "Author");
        DatatypeProperty firstName = tbox.getDatatypeProperty(tBoxDefaultNS + "authorFirstName");
        DatatypeProperty lastName = tbox.getDatatypeProperty(tBoxDefaultNS + "authorLastName");
        ObjectProperty hasAuthorProp = tbox.getObjectProperty(tBoxDefaultNS + "hasAuthor");
        
        for(Author author : authorList) {
            Individual authorIndi = abox.createIndividual(aBoxNS + "AUTHOR-" + author.getId(), authorClass);	// create a Individual object
            authorIndi.addProperty(firstName, author.getFirstname());
            authorIndi.addProperty(lastName, author.getLastname());

            parent.addProperty(hasAuthorProp, authorIndi);
        }

    }
}
